<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class PickupPointVendor extends Model
{
    use HasFactory, SoftDeletes;

    protected $table = 'ims_yz_pickup_point_vendors';

    protected $fillable = [
        'store_id',
        'vendor_id',
        'created_at',
        'updated_at'
    ];

    protected $casts = [
        'created_at' => 'datetime',
        'updated_at' => 'datetime',
        'deleted_at' => 'datetime'
    ];

    // 关联门店
    public function store()
    {
        return $this->belongsTo(Store::class, 'store_id');
    }

    // 关联供应商
    public function vendor()
    {
        return $this->belongsTo(Vendor::class, 'vendor_id', 'id');
    }

    /**
     * 获取指定门店已分配的供应商ID列表
     *
     * @param int $storeId
     * @return array
     */
    public static function getVendorIdsByStore($storeId)
    {
        return self::where('store_id', $storeId)
            ->pluck('vendor_id')
            ->toArray();
    }
}